unit CPPlotExport;

interface

uses Classes, Controls, Graphics, CPBase, CPPlotCanvas;

type
  { This is the base class for exporting the view of a plotter control to
    a certain graphic file format. }
  TCPPlotExport = class(TCPPlotCanvas)
  protected
    { File path of the exported image. This is only needed for surfaces that
      work as image exporters. }
    FFileName: string;
    { Image width in inch. }
    FInchWidth: Double;
    { Image height in inch. }
    FInchHeight: Double;
    { File extension used by file format }
    FFileExtension: string;
  public
    { Creates a new exporter instance with specified size. The size of the
      graphic is specified in inch. For raster formats the image width
      will be InchWidth * UnitsPerInch pixels and the image height will be
      InchHeight * UnitsPerInch pixels. Also UnitsPerInch will scale all
      lengths measured in pt such as line width, font size and grid size.
      @param Control Plotter control
      @param InchWidth Width of graphic in inches
      @param InchHeight Height of graphic in inches
      @param UnitsPerInch Canvas units per inch }
    constructor Create(Control: TCustomControl; InchWidth, InchHeight,
      UnitsPerInch: Double); virtual;
    { File name to use for export }
    property FileName: string read FFileName write FFileName;
    { File extension of file format }
    property FileExtension: string read FFileExtension;
  end;

  TCPPlotExportClass = class of TCPPlotExport;

implementation

uses Types, CPPlotter, Windows, Math;


{ TCPPlotExport }

constructor TCPPlotExport.Create(Control: TCustomControl; InchWidth,
  InchHeight, UnitsPerInch: Double);
begin
  inherited Create(Control);
  FFileName := '';
  FFileExtension := '';
  FInchWidth := InchWidth;
  FInchHeight := InchHeight;
  FUnitsPerInch := UnitsPerInch;
  SetBounds(CPToBounds(0, 0, FInchWidth * FUnitsPerInch,
    FInchHeight * FUnitsPerInch));
end;

end.
